package edu.pxxy.zxl;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;


public class FoodAdapter extends BaseAdapter {
    private List<Food> foodlist;
    private Context context;
    public FoodAdapter(List<Food> foods, Context context){
        this.foodlist=foods;
        this.context=context;
    }



    @Override
    public int getCount() {
        return foodlist.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        View itemView ;
        if(view==null){
            LayoutInflater inflater = LayoutInflater.from(context);
            itemView=inflater.inflate(R.layout.item_list,null);
        }else{
            itemView =view;
        }

       Food fd = foodlist.get(i);
        
        TextView foodname = itemView.findViewById(R.id.tv_name);
        TextView foodprice  = itemView.findViewById(R.id.tv_price);
        TextView count = itemView.findViewById(R.id.tv_count);

        foodname.setText(fd.getFoodName());
        foodprice.setText(fd.getFoodPrice());
        count.setText(fd.getCount());

        return itemView;

    }
}
